/*
 * DiamondShopMenuItem.cpp
 *
 *  Created on: 2015-9-18
 *      Author: 10095427
 */

#include "DiamondShopMenuItem.h"

USING_NS_CC;

#define WIDTH   150
#define HEIGHT  174
#define TEXT_Y   15
#define TITLE_FONT_SIZE  15
#define TITLE_FONT_NAME  "arial"
#define TITLE_X          55
#define TITLE_Y          (HEIGHT - 25)
#define ICON_WIDTH  50
#define ICON_HEIGHT  50
#define ICON_X   4
#define ICON_Y   (HEIGHT-ICON_HEIGHT-4)
#define PRICE_X          60
#define PRICE_Y          (TITLE_Y - 25)
#define INFO_X          0
#define INFO_Y          10
#define INFO_WIDTH      WIDTH
#define INFO_HEIGHT      (100)
#define INFO_FONT_SIZE  16
#define INFO_FONT_NAME  "arial"


typedef enum {
	BgTag=10,
    IconTag,
    TitleTag,
    PriceTag,
    InfoTag,

} MenuItemTag;

typedef enum {
	ZBg,
    ZTitle,

} ZIndex;


DiamondShopMenuItem::DiamondShopMenuItem() {
	// TODO Auto-generated constructor stub

}

DiamondShopMenuItem::~DiamondShopMenuItem() {
	// TODO Auto-generated destructor stub
}

DiamondShopMenuItem * DiamondShopMenuItem::create(const std::string& normalImage, const std::string& selectedImage, const std::string& disabledImage, const ccMenuCallback& callback)
{
    return (DiamondShopMenuItem *)MenuItemImage::create(normalImage, selectedImage, disabledImage, callback);
}

void DiamondShopMenuItem::setTitle(const std::string& title)
{
	if(getChildByTag(TitleTag)){
		removeChildByTag(TitleTag);
	}
    LabelTTF *label = LabelTTF::create(title, TITLE_FONT_NAME, TITLE_FONT_SIZE);
    label->setAnchorPoint(Point(0, 0));
    label->setPosition(TITLE_X,TITLE_Y);
    label->setColor(Color3B::WHITE);
    addChild(label,ZTitle,TitleTag);

}

void DiamondShopMenuItem::setIcon(const std::string& iconName)
{
	if(getChildByTag(IconTag)){
		removeChildByTag(IconTag);
	}
	auto icon = Sprite::createWithSpriteFrameName(iconName);
	icon->setAnchorPoint(Vec2::ZERO);
	icon->setPosition(Point(ICON_X,ICON_Y));
	this->addChild(icon,IconTag);
}

void DiamondShopMenuItem::setPrice(const std::string& price)
{
	if(getChildByTag(PriceTag)){
		removeChildByTag(PriceTag);
	}
    LabelTTF *label = LabelTTF::create(price, TITLE_FONT_NAME, TITLE_FONT_SIZE);
    label->setAnchorPoint(Point(0, 0));
    label->setPosition(PRICE_X,PRICE_Y);
    label->setColor(Color3B::BLUE);
    addChild(label,ZTitle,PriceTag);

}

void DiamondShopMenuItem::setInfo(const std::string& info)
{
	if(getChildByTag(InfoTag)){
		removeChildByTag(InfoTag);
	}
    LabelTTF *label = LabelTTF::create(info, INFO_FONT_NAME, INFO_FONT_SIZE,Size(INFO_WIDTH,INFO_HEIGHT));
    label->setAnchorPoint(Point(0, 0));
    label->setPosition(INFO_X,INFO_Y);
    label->setColor(Color3B::ORANGE);
    addChild(label,ZTitle,InfoTag);

}

Size  DiamondShopMenuItem::getSize()
{
    return Size(WIDTH,HEIGHT);
}
